﻿using System;
using System.Collections.Generic;
using System.Linq;
using phudieuhungthinh.BL.Model;
using phudieuhungthinh.DAL.Repositories;

namespace phudieuhungthinh.BL
{
    public class FeatureArticleImpl
    {
        #region Methods

        public List<FeatureArticleModel> GetFeatureArticles(ArticleType type, bool isPublished)
        {
            try
            {
                var articleRep = new ArticleRepository();
                var featureArticleRep = new FeatureArticleRepository();
                var articles = (from x in featureArticleRep.QueryFeatureArticle()
                                join y in articleRep.QueryArticle(y => y.ArticleType == (int)type)
                                    on x.ArticleID equals y.ID
                                where y.IsPublished == isPublished
                                select x).ToList().Select(x => new FeatureArticleModel(x)).ToList();
                return articles;
            }
            catch (Exception)
            {
                return null;
            }
        }

        #endregion
    }
}